const fp = require('lodash/fp');
const { Maybe, Container } = require('./support');

// 练习1
let maybe = Maybe.of([5, 6, 1]);
let ex1 = () => {
    let add = fp.map(fp.add(1))
    return maybe.map(x => add(x))
}
let result1 = ex1()
console.log(result1);


//  练习2
let xs = Container.of(['do', 'ray', 'me', 'fa', 'so', 'la', 'ti', 'do']);

let ex2 = () =>{
    return xs.map(x => fp.first(x))
}

let result2 = ex2()
console.log(result2);


// 练习3
let safeProp = fp.curry(function(x, o) {
    return Maybe.of(o[x])
})

let user = { id: 2, name: 'Albert'}
let ex3 = () => {
    return safeProp('name', user).map(x => fp.first(x))
}

let result3 = ex3()
console.log(result3);


// 练习4
let ex4 = (n) => {
    return Maybe.of(n).map(() => parseInt(n))
}

let result4 = ex4('32')
console.log(result4);
